﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Direct.Security;

namespace Direct.Mvc
{
    public class AuthController : ServerControllerBase
    {
        public ViewResult LogonView()
        {
            return View("Logon");
        }

        // u = username, p = password, n = fwd url
        public JsonResult Logon(String u, String p, String n)
        {
            var authService = ServiceLocator.GetInstance<IAuthenticationService>();
            var msg = "";
            var success = authService.PerformLogon(u, p, out msg);

            var result = new
            {
                loggedOn = success,
                msg = success ? "" : msg,
                next = n
            };
            return Json(result);
        }

        public ActionResult Logout()
        {
            var authService = ServiceLocator.GetInstance<IAuthenticationService>();
            authService.PerformLogout();
            return Redirect("/r/loggedOut");
        }
    }
}
